﻿using System;
using BBICMS.Model;
using BBICMS.Model.Security;
using BBICMS.Data.Repositories.Identity;
using BBICMS.Model.Works;

namespace BBICMS.Repository
{
    public class ApplicationUnit : IDisposable
    {
        private DataContext _context = new DataContext();

        private IRepository<Position> _positions = null;
        private IRepository<Advertisement> _advertisements = null;

        private IRepository<Blog> _blogs = null;
        private IPostRepository _posts = null;

        private ICategoryRepository _categories = null;       

        private IRepository<Carousel> _carousels = null;

        private IRepository<Team> _teams = null;

        #region pages
        private IRepository<Page> _pages = null;
        private IRepository<PageLang> _pageLangs = null;

        public IRepository<PageLang> PageLangs
        {
            get
            {
                if (this._pageLangs == null)
                {
                    this._pageLangs = new PageLangRepository(this._context);
                }
                return this._pageLangs;
            }
        }

        public IRepository<Page> Pages
        {
            get
            {
                if (this._pages == null)
                {
                    this._pages = new PageRepository(this._context);
                }
                return this._pages;
            }
        }
        #endregion

        #region language
        private IRepository<Language> _languages = null;
        public IRepository<Language> Languages
        {
            get
            {
                if (this._languages == null)
                {
                    this._languages = new LanguageRepository(this._context);
                }
                return this._languages;
            }
        }

        #endregion


        #region product
        //private IRepository<BLayout> _blayouts = null;
        //private IRepository<QLayout> _qlayouts = null;
        //private IRepository<BSize> _bsizes = null;
        //private IRepository<QSize> _qsizes = null;
        //private IRepository<Color> _colors = null;
        //private IRepository<ColorLang> _colorLangs = null;
        //private IRepository<Serie> _series = null;
        //private IRepository<SerieLang> _serieLangs = null;
        private IRepository<ProductCategory> _productCategories = null;
        private IRepository<ProductCategoryLang> _productCategoryLangs = null;
        private IRepository<Product> _products = null;
        private IRepository<ProductPhoto> _productPhotos = null;
        private IRepository<Collection> _collections = null;

        public IRepository<Collection> Collections
        {
            get
            {
                if (this._collections == null)
                {
                    this._collections = new CollectionRepository(this._context);
                }
                return this._collections;
            }
        }

        //public IRepository<QLayout> QLayouts
        //{
        //    get
        //    {
        //        if (this._qlayouts == null)
        //        {
        //            this._qlayouts = new QLayoutRepository(this._context);
        //        }
        //        return this._qlayouts;
        //    }
        //}

        //public IRepository<BLayout> BLayouts
        //{
        //    get
        //    {
        //        if (this._blayouts == null)
        //        {
        //            this._blayouts = new BLayoutRepository(this._context);
        //        }
        //        return this._blayouts;
        //    }
        //}

        //public IRepository<BSize> BSizes
        //{
        //    get
        //    {
        //        if (this._bsizes == null)
        //        {
        //            this._bsizes = new BSizeRepository(this._context);
        //        }
        //        return this._bsizes;
        //    }
        //}

        //public IRepository<QSize> QSizes
        //{
        //    get
        //    {
        //        if (this._qsizes == null)
        //        {
        //            this._qsizes = new QSizeRepository(this._context);
        //        }
        //        return this._qsizes;
        //    }
        //}

        //public IRepository<Color> Colors
        //{
        //    get
        //    {
        //        if (this._colors == null)
        //        {
        //            this._colors = new ColorRepository(this._context);
        //        }
        //        return this._colors;
        //    }
        //}

        //public IRepository<ColorLang> ColorLangs
        //{
        //    get
        //    {
        //        if (this._colorLangs == null)
        //        {
        //            this._colorLangs = new ColorLangRepository(this._context);
        //        }
        //        return this._colorLangs;
        //    }
        //}

        //public IRepository<Serie> Series
        //{
        //    get
        //    {
        //        if (this._series == null)
        //        {
        //            this._series = new SerieRepository(this._context);
        //        }
        //        return this._series;
        //    }
        //}

        //public IRepository<SerieLang> SerieLangs
        //{
        //    get
        //    {
        //        if (this._serieLangs == null)
        //        {
        //            this._serieLangs = new SerieLangRepository(this._context);
        //        }
        //        return this._serieLangs;
        //    }
        //}

        public IRepository<ProductCategory> ProductCategories
        {
            get
            {
                if (this._productCategories == null)
                {
                    this._productCategories = new ProductCategoryRepository(this._context);
                }
                return this._productCategories;
            }
        }
        public IRepository<ProductCategoryLang> ProductCategoryLangs
        {
            get
            {
                if (this._productCategoryLangs == null)
                {
                    this._productCategoryLangs = new ProductCategoryLangRepository(this._context);
                }
                return this._productCategoryLangs;
            }
        }
        public IRepository<Product> Products
        {
            get
            {
                if (this._products == null)
                {
                    this._products = new ProductsRepository(this._context);
                }
                return this._products;
            }
        }

        public IRepository<ProductPhoto> ProductPhotos
        {
            get
            {
                if (this._productPhotos == null)
                {
                    this._productPhotos = new ProductPhotosRepository(this._context);
                }
                return this._productPhotos;
            }
        }


        #endregion

        #region Security

        private IUserRepository _users = null;
        private IRepository<Role> _roles = null;
        private IMenuRepository _menus = null;
      

        public IUserRepository Users
        {
            get
            {
                if (this._users == null)
                {
                    this._users = new UserRepository(this._context);
                }
                return this._users;
            }
        }


        public IRepository<Role> Roles
        {
            get
            {
                if (this._roles == null)
                {
                    this._roles = new RoleRepository(this._context);
                }
                return this._roles;
            }
        }

        public IMenuRepository Menus
        {
            get
            {
                if (this._menus == null)
                {
                    this._menus = new MenuRepository(this._context);
                }
                return this._menus;
            }
        }
        #endregion
        private IRepository<Link> _links = null;
        private IRepository<LinkCategory> _linkCategories = null;

        public IRepository<LinkCategory> LinkCategories
        {
            get
            {
                if (this._linkCategories == null)
                {
                    this._linkCategories = new LinkCategoryRepository(this._context);
                }
                return this._linkCategories;
            }
        }

        public IRepository<Link> Links
        {
            get
            {
                if (this._links == null)
                {
                    this._links = new LinkRepository(this._context);
                }
                return this._links;
            }
        }

#region Works

        private IRepository<Work> _works = null;
        public IRepository<Work> Works => this._works ?? (this._works = new WorkRepository(this._context));
        private IRepository<WorkType> _workTypes = null;
        public IRepository<WorkType> WorkTypes => this._workTypes ?? (this._workTypes = new WorkTypeRepository(this._context));
        private IRepository<Solution> _solutions = null;
        public IRepository<Solution> Solutions => this._solutions ?? (this._solutions = new SolutionRepository(this._context));

        private IRepository<Client> _clients = null;
        public IRepository<Client>  Clients => this._clients ?? (this._clients = new ClientRepository(this._context));

        #endregion

        public IRepository<Team> Teams
        {
            get
            {
                if (this._teams == null)
                {
                    this._teams = new TeamRepository(this._context);
                }
                return this._teams;
            }
        }

        public IRepository<Carousel> Carousels
        {
            get
            {
                if (this._carousels == null)
                {
                    this._carousels = new CarouselRepository(this._context);
                }
                return this._carousels;
            }
        }

        public IRepository<Position> Positions
        {
            get
            {
                if (this._positions == null)
                {
                    this._positions = new PositionsRepository(this._context);
                }
                return this._positions;
            }
        }

        public IRepository<Advertisement> Advertisements
        {
            get
            {
                if (this._advertisements == null)
                {
                    this._advertisements = new AdvertisementsRepository(this._context);
                }
                return this._advertisements;
            }
        }

        public IRepository<Blog> Blogs
        {
            get
            {
                if (this._blogs == null)
                {
                    this._blogs = new BlogsRepository(this._context);
                }
                return this._blogs;
            }
        }


        public IPostRepository Posts
        {
            get
            {
                if (this._posts == null)
                {
                    this._posts = new PostsRepository(this._context);
                }
                return this._posts;
            }
        }

        public ICategoryRepository Categories
        {
            get
            {
                if (this._categories == null)
                {
                    this._categories = new CategoriesRepository(this._context);
                }
                return this._categories;
            }
        }


      


        public void SaveChanges()
        {
            this._context.SaveChanges();
        }

        public void Dispose()
        {
            if (this._context != null)
            {
                this._context.Dispose();
            }
        }
    }
}
